<%@ include file="/taglibs.jsp"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<fmt:message key="date.format" var="df" scope="page"/>

<head>
	<title><fmt:message key="file.search.title"/></title>
	<script type="text/javascript" src="${ctx}/scripts/file_module.js"></script>
</head>

<s:set name="files" value="fileList" scope="request"/>

<s:form name="filterForm" id="filterForm" action="files-submit" method="post">
    <s:select key="file.field" name="fieldId" cssStyle="max-width: 500px !important;" list="fields" listKey="id" listValue="name" headerKey="%{getText('select.default.key')}" headerValue="%{getText('select.default.value')}"></s:select>
 	<s:select key="file.category" name="cateId" cssStyle="max-width: 500px !important;" list="catList" listKey="value" listValue="name" headerKey="%{getText('select.default.key')}" headerValue="%{getText('select.default.value')}"></s:select>   
 	<s:select key="file.status" name="fileStatusId" list="fileStatuses" listKey="id" listValue="status" headerKey="%{getText('select.default.key')}" headerValue="%{getText('select.default.value')}"></s:select>
<table>
	   
<tr>
	<td width="120px">
        <s:property value="getText('file.input.fromDate')"/>
    </td>
    <td>
        <s:textfield id="fromDate" readonly="true" name="fromDate" size="11" theme="simple"/>
        <button id="fromDateCal" type="button" class="button"> ... </button> 
    </td>
    <td>
        <s:property value="getText('file.input.toDate')"/>
    </td>
	<td>
		<s:textfield id="toDate" readonly="true" name="toDate" size="11" theme="simple"/>
        <button id="toDateCal" type="button" class="button"> ... </button> 
	</td>
</tr>
<tr>
	<td width="110px">
        <s:property value="getText('file.sender')"/>
    </td>
	<td width="250px">
		<s:textfield id="sender" name="sender" size="30" theme="simple"/>
	</td>
	<td width="100px">
        <s:property value="getText('file.id')"/>
    </td>
	<td>
		<s:textfield id="fileId" name="fileId" size="11" theme="simple"/>
	</td>
</tr>
<tr>
	<td colspan="4">
				<button type="submit" onclick="this.blur()" class="button" name="search" >
					<fmt:message key="button.search.title"></fmt:message>
					<img src="${ctx}/images/btn_search.png" align="left" height="20"
						width="20">
				</button>
	</td>
</tr>
</table>
</s:form>
<s:set var="item_name" value="%{getText('file.item_name')}" scope="page"></s:set>
<s:set var="items_name" value="%{getText('file.items_name')}" scope="page"></s:set>
<s:form name="mForm" id="mForm" action="removeFileWithId" method="post" validate="true">
<s:hidden name="fieldId"/>
<s:hidden name="cateId"/>
<s:hidden name="fileStatusId"/>
<s:hidden name="fromDate"/>
<s:hidden name="toDate"/>
<s:hidden name="fileId"/>
<s:hidden name="sender"/>
<p></p>

<%-- <div align="right">
	
	<a href="${ctx}/exportDocFile!exportSeachFiles.html">
		<img src="${ctx}/images/export_word.png">
	</a>
</div> --%>
	
<display:table name="files" class="table" requestURI="" id="file" >
    <display:setProperty name="paging.banner.item_name" value="${item_name}"/>
<display:setProperty name="paging.banner.items_name" value="${items_name}" />
    <display:column property="submitter" sortable="false" titleKey="file.sender" escapeXml="true"/>
    <%--<display:column property="senderPhone" sortable="true" titleKey="file.senderPhone" escapeXml="true"/> --%>
    <display:column style="width:80px" sortable="true" titleKey="file.inputDate" escapeXml="true" sortProperty="inputDate">
    	<joda:format value="${file.inputDate}" pattern="dd/MM/yyyy"/>
    </display:column>
    <display:column style="width:80px" sortable="true" titleKey="file.outputDate" escapeXml="true" sortProperty="outputDate">
    	<joda:format value="${file.outputDate}" pattern="dd/MM/yyyy"/>
    </display:column>
<%--     <display:column sortable="true" titleKey="file.dateCompleted" escapeXml="true" sortProperty="dateCompleted">
    	<joda:format value="${file.dateCompleted}" pattern="dd/MM/yyyy"/>
    </display:column>
    <display:column sortable="true" titleKey="file.dateGetResult" escapeXml="true" sortProperty="dateGetResult">
    	<joda:format value="${file.dateGetResult}" pattern="dd/MM/yyyy"/>
    </display:column> --%>
     <display:column property="currentUserFullName" sortProperty="currentUser" sortable="false" titleKey="currentUser.fullName" escapeXml="true"/>
     <display:column style="width:120"  sortable="true" titleKey="file.status" escapeXml="true">
     	<c:if test="${file.currentUserFullName eq null and file.dateCompleted eq null}">
     		<s:text name="fileStatus.status.refused"/>
     	</c:if>
     	<c:if test="${file.dateCompleted ne null and file.dateGetResult eq null}">
     		<s:text name="fileStatus.status.finished"/>
     	</c:if>
     	<c:if test="${file.dateCompleted ne null and file.dateGetResult ne null}">
     		<s:text name="fileStatus.status.returned"/>
     	</c:if>
     	<c:if test="${file.currentUserFullName ne null}">
     		${file.fileStatus.status}
     	</c:if>
     </display:column>
      <display:column style="width:30px" sortable="true" href="viewFile.html" media="html" paramId="id" paramProperty="id" titleKey="button.detail.title">
        Xem
    </display:column>
     <s:if test="fileList.fullListSize != 0">
     	<c:if test="${file.dateCompleted eq null and file.dateGetResult eq null and file.currentUserFullName ne null and file.fileStatus.id == 1 }">
		    <display:column title="<input type='checkbox' class='checkAll'>" >
		    	<input type="checkbox" class="cb-element" value="${file.id}" name="ids">
		    </display:column>
	    </c:if>
    </s:if>
    
</display:table>

<div align="right">
	
	<s:if test="fileList.fullListSize != 0">
		
			<button type="button" class="button" name="delete" onclick="$('#mForm').submit();"">
				<fmt:message key="button.delete.title"></fmt:message>
				<img src="${ctx}/images/btn_cancel.png" align="left" height="20" width="20">
			</button>
		
	</s:if>
</div>

</s:form>
<br>
<div class="msg info"><fmt:message key="file.help.delete"></fmt:message></div>
<script type="text/javascript">

$(document).ready(function (){
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	if(month < 10) month = "0" + month;
	if(day < 10) day = "0" + day;
	var year = currentTime.getFullYear();
	
	var today = day + "/" + month + "/" + year;
	
	if($("#fromDate").val()=="")
  		$("#fromDate").val(today);
	
	if($("#toDate").val()=="")
  		$("#toDate").val(today);
});

new Calendar({
	inputField: "fromDate",
	dateFormat: "%d/%m/%Y",
	trigger: "fromDateCal",
	bottomBar: false,
	onSelect: function() { this.hide(); }
});

$( '.cb-element' ).live('change', function(){
	$( '.cb-element' ).length == $( '.cb-element:checked' ).length ? 
			$( '.checkAll' ).attr( 'checked', 'checked' ): $( '.checkAll' ).attr( 'checked', '' );
	$( this ).next().val($( this ).is( ':checked' ));
});
$( '.checkAll' ).live('change', function(){
	$( '.cb-element' ).attr('checked', $( this ).is( ':checked' ) ? 'checked' : '');
	var chkAll = $( this );
	$( '.cb-element' ).each(function(){
		$( this ).next().val(chkAll.is( ':checked' ));
	});
});
</script>
